<template>
  <el-container class="app-container">
    <el-page-header @back="$router.back()" :content="`租户/企业管理${pageTitleFilter[this.pageType]}`" class="fl"></el-page-header>
    <el-form ref="form" :model="form" :rules="rules" :disabled="true" label-width="140px">
<!--  <el-header></el-header>-->
      <el-card class="box-card m-t-10">
        <div slot="header" class="clearfix  box-card-h">
          <span>租户/企业</span>
        </div>
        <div>
          <el-row class="p-style">
            <el-col :span="8">
              <el-form-item prop="name" label="名称：">
                <el-input v-model.trim='form.name' placeholder="请输入"></el-input>
              </el-form-item>
              <el-form-item prop="industryType" label="行业分类：">
                <el-input v-model.trim='form.industryType' placeholder="请输入"></el-input>
              </el-form-item>
              <el-form-item prop="identNumber" label="证件号码：">
                <el-input v-model.trim='form.identNumber' placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
            <el-form-item prop="contactName" label="联系人：">
            <el-input v-model.trim='form.contactName' placeholder="请输入"></el-input>
          </el-form-item>
            <el-form-item prop="contactMobile" label="联系人电话：">
              <el-input v-model.trim='form.contactMobile' placeholder="请输入"></el-input>
            </el-form-item>
            <el-form-item prop="contactEmail" label="联系人邮箱：">
              <el-input v-model.trim='form.contactEmail' placeholder="请输入"></el-input>
            </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="remark" label="备注：">
                <el-input v-model.trim='form.remark' type="textarea" placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-card>

      <el-divider></el-divider>
      <el-card class="box-card">
        <div slot="header" class="clearfix  box-card-h">
          <span>服务标签</span>
        </div>
        <div>
          <!--<el-tag
            class="tags"
            v-for="(item,i) in severLabels"
            :key="i"
            :type="success"
            effect="dark">
            {{ item.labelName }}
          </el-tag>-->

          <el-select
            style="width: 400px"
            v-model="form.labelIds"
            multiple
            placeholder="请选择">
            <el-option
              v-for="(item,i) in severLabels"
              :key="i"
              :label="item.labelName"
              :value="item.id">
            </el-option>
          </el-select>
          <el-button type="" size="mini" icon="el-icon-plus" @click="addLabel">新增标签</el-button>

        </div>
      </el-card>

      <el-divider></el-divider>
      <el-card class="box-card">
        <div slot="header" class="clearfix  box-card-h">
          <span>工商信息</span>
        </div>
        <div>
          <el-row class="p-style">
            <el-col :span="8">
              <el-form-item prop="socialCreditDoce" label="统一社会信用代码：">
                <el-input v-model.trim='form.socialCreditDoce' placeholder="请输入"></el-input>
              </el-form-item>
              <el-form-item prop="registerId" label="注册号：">
                <el-input v-model.trim='form.registerId' placeholder="请输入"></el-input>
              </el-form-item>
              <el-form-item prop="organizationCode" label="组织机构代码：">
                <el-input v-model.trim='form.organizationCode' placeholder="请输入"></el-input>
              </el-form-item>
              <el-form-item prop="industry" label="所属行业：">
                <el-input v-model.trim='form.industry' placeholder="请输入"></el-input>
              </el-form-item>
              <el-form-item prop="companyType" label="公司类型：">
                <el-input v-model.trim='form.companyType' placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="legalRepesentative" label="法定代表人：">
                <el-input v-model.trim='form.legalRepesentative' placeholder="请输入"></el-input>
              </el-form-item>
              <el-form-item prop="financingAmount" label="注册资本(万)：">
                <el-input v-model.trim='form.financingAmount' type="number" placeholder="请输入"></el-input>
              </el-form-item>
              <el-form-item prop="businessStatus" label="经营状态：">
                <el-input v-model.trim='form.businessStatus' placeholder="请输入"></el-input>
              </el-form-item>
              <el-form-item prop="establishDate" label="成立日期：">
                <el-input v-model.trim='form.establishDate' placeholder="请输入"></el-input>
              </el-form-item>
              <el-form-item prop="approvalDate" label="核准日期：">
                <el-input v-model.trim='form.approvalDate' placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="registrationAuthority" label="登记机关：">
                <el-input v-model.trim='form.registrationAuthority' placeholder="请输入"></el-input>
              </el-form-item>
              <el-form-item prop="registerAddress" label="注册地址：">
                <el-input v-model.trim='form.registerAddress' placeholder="请输入"></el-input>
              </el-form-item>
              <el-form-item prop="regionDetail" label="所属区域：">
                <el-input v-model.trim='form.regionDetail' placeholder="请输入"></el-input>
              </el-form-item>
              <el-form-item prop="businessScope" label="经营范围：">
                <el-input v-model.trim='form.businessScope' type="textarea" placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-card>

      <el-divider></el-divider>
      <el-card class="box-card">
        <div slot="header" class="clearfix  box-card-h">
          <span>发票信息</span>
        </div>
        <div>
          <el-row class="p-style">
            <el-col :span="8">
              <el-form-item prop="depositeBank" label="开户银行：">
                <el-input v-model.trim='form.depositeBank' placeholder="请输入"></el-input>
              </el-form-item>
              <el-form-item prop="mobile" label="电话：">
                <el-input v-model.trim='form.mobile' placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="bankAccount" label="账号：">
                <el-input v-model.trim='form.bankAccount' placeholder="请输入"></el-input>
              </el-form-item>
              <el-form-item prop="invoiceAddress" label="开票地址：">
                <el-input v-model.trim='form.invoiceAddress' placeholder="请输入"></el-input>
              </el-form-item>

            </el-col>
            <el-col :span="8">
              <el-form-item prop="taxId" label="纳税人识别号：">
                <el-input v-model.trim='form.taxId' placeholder="请输入"></el-input>
              </el-form-item>
              <el-form-item prop="invoiceType" label="默认发票类型：">
                <el-input v-model.trim='form.invoiceType' placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-card>
      <el-card class="box-card" v-if="pageType!=='view'">

          <el-button type="primary" @click="onSubmit">保存</el-button>
          <el-button @click="()=>{this.$router.go(-1)}">取消</el-button>

      </el-card>

    </el-form>


    <el-dialog title="新增标签" :visible.sync="dialogAddLabel" width="60%"
               :destroy-on-close="true">
      <el-form ref="form" :model="formLabel" :rules="rulesLabel" label-width="120px" style="width: 90%">
        <el-form-item prop="labelName" label="标签名称:">
            <el-input v-model.trim="formLabel.labelName"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmitLabel">保存</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-footer></el-footer>
  </el-container>
</template>

<script>
  import Tinymce from '@/components/Tinymce'

  import * as pageApi from '@/api/shopBusiness/tenantManageList'

  import * as commonApi from '@/api/common'

  export default {
    name: 'add',
    components: {
      Tinymce
    },
    data() {
      const monthAgeValidator = (rule, value, callback) => {
        if(!value.toString() || !this.form.endMonthAge.toString()){
          callback(new Error('请选择完整的月龄范围'))
        }else{
          callback()
        }
      }
      return {
        pageTitleFilter:{'view':'查看','update':'编辑'},
        dialogAddLabel:false,
        pageType:'',
        severLabels:[],
        formLabel:{
          labelName:'',
          labelType:''
        },
        rulesLabel:[{
          labelName: { required: true, trigger: 'blur', message: '名称不能为空' },
        }],
        form: {
          "approvalDate": "",
          /*"attachment": [
            {
              "name": "",
              "url": ""
            }
          ],*/
          "bankAccount": "",
          "businessIncome": '',
          "businessScope": "",
          "businessStatus": "",
          "companyType": "",
          "contactEmail": "",
          "contactMobile": "",
          "contactName": "",
          "depositeBank": "",
          "enterprisesNumber": '',
          "establishDate": "",
          "extra": "",
          "financingAmount": '',
          "financingStage": true,
          "identNumber": "",
          "industry": "",
          "industryType": "",
          "invoiceAddress": "",
          "invoiceType": "",
          "labelId": "",
          "legalRepesentative": "",
          "mobile": "",
          "name": "",
          "organizationCode": "",
          "profitsTaxes": '',
          "propertyRightsNumber": '',
          "regionDetail": "",
          "registerAddress": "",
          "registerCapital": "",
          "registerId": "",
          "registrationAuthority": "",
          "remark": "",
          "score": '',
          "socialCreditDoce": "",
          "status": '',
          "taxId": "",
          "tenantId": '',
          "tenantName": "",
          "tenantryId": ''
        },
        rules: {
          name: [
            { required: true, trigger: 'blur', message: '名称不能为空' },
          ],
        }

      }
    },
    methods: {
      addLabel(){
        this.formLabel = {
          labelName:'',
          labelType:1
        }
        this.dialogAddLabel = true
      },
      onSubmitLabel(){
        commonApi.addLabel(this.formLabel).then(res=>{
          this.handleMessage(res)
          if(res.code === '200'){
            this.dialogAddLabel = false
            this.getAllLabel()
          }
        })
      },
      handleUpload(url, obj) {
        this.form[obj.name] = url
      },
      handleRes(res) {
        let _this = this
        this.handleMessage(res)
        if (res.code === '200') {
          _this.$router.go(-1)
        }
      },
      onSubmit() {
        let _this = this
        let { id } = _this.$route.query
        let post = Object.assign({},_this.form)
        post.labelIds = post.labelIds.join(",")
        _this.$refs['form'].validate((valid) => {
          if (valid) {
            if (!id) {
              pageApi.create(post).then((res) => {
                _this.handleRes(res)
              })
            } else {
              pageApi.update(id,post).then((res) => {
                _this.handleRes(res)
              })
            }

          } else {
            return false
          }
        })
      },
      backClick() {
        this.$router.go(-1)
      },
      getById(id) {
        pageApi.getById(id).then(res => {
          this.form = Object.assign({}, this.form, res.body)
        })
      },
      getAllLabel(){
        //服务标签
        commonApi.getAllLabel(1).then(res=>{
          this.severLabels = res.body
          })
      },
    },
    created: function() {
      this.getAllLabel()
      let { id,pageType } = this.$route.query
      this.pageType = pageType
      if (id) {
        this.form.tenantryId = id
        this.getById(id)
      }
    }
  }
</script>

<style lang="scss" scoped>
.tags{
  margin-right: 10px;
}
.p-style{
  font-pageSize: 14px;
}
.box-card{
  .box-card-h{
    font-pageSize: 16px;
    font-weight: 500;
  }
}
</style>
